
# Definition for a Node.
class Node:
    def __init__(self, val=None, children=None):
        self.val = val
        self.children = children

root=Node(1)
ch1=Node(3)
ch2=Node(2)
ch3=Node(4)
ch4=Node(5)
ch5=Node(6)
root.children=[ch1,ch2,ch3]
ch1.children=[ch4,ch5]

def dfs(root,ans):
    #出口函数
    if root.children==None:
        ans.append(root.val)
        return None
    else:
        for node in root.children:
            dfs(node,ans)
        ans.append(root.val)

def postorder(root):
    if root==None:
        return []
    ans=[]
    dfs(root,ans)
    return ans
print(postorder(root))